#ifndef _SRC_DFU_AWI_DFU_PACK_H_
#define _SRC_DFU_AWI_DFU_PACK_H_

#include "awi_util.h"
#include "checksum.h"

#ifdef __cplusplus
extern "C" {
#endif

#define AWI_DFU_PROTOCOL_HEADER_LENGTH sizeof(struct _dfu_header)
#define AWI_DFU_PROTOCOL_MAGIC_NUMBER 0xFFA5
#define AWI_DFU_PROTOCOL_VERSION 1

#define _DFU_DEVICEINFO_PRODUCT_NAME_SHIFT 0
#define _DFU_DEVICEINFO_PHYSICAL_SHIFT 1
#define _DFU_DEVICEINFO_SOFTWARE_SHIFT 2
#define _DFU_DEVICEINFO_SERIAL_NUMBER_SHIFT 3
#define _DFU_DEVICEINFO_UNIQUE_ID_SHIFT 4

#pragma pack(1)
struct  _dfu_header{
	uint16_t magic;
	uint16_t version;
	uint16_t dst;
	uint16_t src;
	uint16_t ctrl;
	uint16_t len;
	uint16_t crc;
};

struct _dfu_bininfo {
	uint32_t flash_block;
	uint32_t slice_size;
	uint32_t slices_total;
	uint32_t bin_size;
	uint8_t bin_md5[16];
};
#pragma pack()

int awi_dfu_pack_proc(uint8_t* buffer, int bytes, uint16_t dst, uint16_t src, uint16_t ctrl, const uint8_t *payload, uint16_t len);
int awi_dfu_pack_header(uint8_t *buffer, uint16_t dst, uint16_t src, uint16_t ctrl, uint16_t len);

#ifdef __cplusplus
};
#endif
#endif /* _SRC_DFU_AWI_DFU_PACK_H_ */